package com.yifeng.repo.micro.service.server.engine.core.temp;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 消息渠道枚举
 */
@Getter
@AllArgsConstructor
public enum MsgChannelEnum {
    SMS("sms", "短信"),
    WX("wx", "微信公众号"),
    WX_MP("wxmp", "微信小程序"),
    WXWORK("wxwork", "企业微信");

    @EnumValue
    @JsonValue
    private final String code;

    private final String name;

    private static final Map<String, MsgChannelEnum> mappings = new HashMap<>(8);

    static {
        for (MsgChannelEnum msgChannel : values()) {
            mappings.put(msgChannel.getCode(), msgChannel);
        }
    }

//    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static MsgChannelEnum resolve(String code) {
        return (code != null ? mappings.get(code) : null);
    }
}
